<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>赛事视频管理</title>
<meta name="decorator" content="default"/>
<script type="text/javascript" src="${ctxStatic}/common/model.js"></script>
<script type="text/javascript">
	//url
	var listUrl = '${ctx}/cms/racevideo/';
	var cardUrl = '${ctx}/cms/racevideo/form';

	//按钮状态  {状态值为 0 不可用 ；1 可用}
	var buttonStatus = {};
	buttonStatus.add 	= {add:{id:'btnAdd',st:0},edit:{id:'btnEdit',st:0},save:{id:'btnSubmit',st:1},cancel:{id:'btnCancel',st:1},back:{id:'btnBack',st:1}};
	buttonStatus.edit	= {add:{id:'btnAdd',st:0},edit:{id:'btnEdit',st:0},save:{id:'btnSubmit',st:1},cancel:{id:'btnCancel',st:1},back:{id:'btnBack',st:1}};
	buttonStatus.save   = {add:{id:'btnAdd',st:1},edit:{id:'btnEdit',st:1},save:{id:'btnSubmit',st:0},cancel:{id:'btnCancel',st:0},back:{id:'btnBack',st:1}};
	buttonStatus.cancel = {add:{id:'btnAdd',st:1},edit:{id:'btnEdit',st:"${not empty racevideo.id?'1':'0'}"},save:{id:'btnSubmit',st:0},cancel:{id:'btnCancel',st:0},back:{id:'btnBack',st:1}}
	buttonStatus.other  = {add:{id:'btnAdd',st:1},edit:{id:'btnEdit',st:"${not empty racevideo.id?'1':'0'}"},save:{id:'btnSubmit',st:0},cancel:{id:'btnCancel',st:0},back:{id:'btnBack',st:1}};

	$(document).ready(function() {
		//$("#name").focus();
		$("#inputForm").validate({
			submitHandler: function(form){
				loading('正在提交，请稍等...');
				form.submit();
			},
			errorContainer: "#messageBox",
			errorPlacement: function(error, element) {
				$("#messageBox").text("输入有误，请先更正。");
				if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
					error.appendTo(element.parent().parent());
				} else {
					error.insertAfter(element);
				}
			}
		});
		
		var currentOpt = "${opt}";
		if(currentOpt==null||currentOpt==''){
			currentOpt = 'other';
		}
		var btnStatus = buttonStatus[currentOpt];
		freshButtonStatus(btnStatus);
		if(currentOpt=='add' || currentOpt=='edit'){
			setAllPageEnable(jQuery("#formAreaId"));
		}else{
			setAllPageDisable(jQuery("#formAreaId"));
		}
	});
	
	function add(){ //新增记录
		var url = cardUrl+"?opt=add";
		window.location.href = url;
	}
	
	function edit(){ //修改记录
		var btnStatus = buttonStatus['edit'];
		freshButtonStatus(btnStatus);
		setAllPageEnable(jQuery("#formAreaId"));
	}
	
	function cancel(){ //取消操作
		var btnStatus = buttonStatus['cancel'];
		freshButtonStatus(btnStatus);
		setAllPageDisable(jQuery("#formAreaId"));
	}
	
	function back(){ //返回
		var btnStatus = buttonStatus['other'];
		freshButtonStatus(btnStatus);
		setAllPageDisable(jQuery("#formAreaId"));
		parent.freshTabs(jQuery(window.parent.document).find('[link="iframeContent1"]'));
	}
	
	function save(){
		var form = $("#inputForm")[0];
		form.submit();
	}
</script>
</head>
<body>
	<form:form id="inputForm" modelAttribute="racevideo" action="${ctx}/cms/racevideo/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>	
		
		<div class="breadcrumb form-search" id="toolButtonId">
			<shiro:hasPermission name="cms:category:edit">
				<input id="btnAdd" class="btn btn-primary" type="button" value="新 增" onclick="add()"/>&nbsp;
				<input id="btnEdit" class="btn btn-primary" type="button" value="修 改" onclick="edit()"/>&nbsp;
				<input id="btnSubmit" class="btn btn-primary" type="button" value="保 存"  onclick="save()"/>&nbsp;
				<input id="btnCancel" class="btn" type="button" value="取 消" onclick="cancel()"/>
			</shiro:hasPermission>
			<input id="btnBack" class="btn" type="button" value="返 回" onclick="back()"/>
		</div>
		
		<div id="formAreaId">
			<div class="control-group">
				<label class="control-label">编码：</label>
				<div class="controls">
					<form:input path="code" htmlEscape="false" maxlength="50" class="input-xlarge "/>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">名称：</label>
				<div class="controls">
					<form:input path="name" htmlEscape="false" maxlength="100" class="input-xlarge "/>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">简介：</label>
				<div class="controls">
					<form:textarea path="brefintrol" htmlEscape="false" rows="4" maxlength="500" class="input-xxlarge "/>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">图片配置：</label>
				<div class="controls">
					<form:input path="brefimage" htmlEscape="false" maxlength="255" class="input-xlarge "/>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">访问次数：</label>
				<div class="controls">
					<form:input path="hits" htmlEscape="false" maxlength="11" class="input-xlarge  digits"/>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">备注信息：</label>
				<div class="controls">
					<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="500" class="input-xxlarge "/>
				</div>
			</div>
		</div>
	</form:form>
</body>
</html>